package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Employeeshift;
import com.restaurant.service.EmployeeshiftService;

public class EmployeeshiftServiceImpl implements EmployeeshiftService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeshift addOrModify( Employeeshift objEmployeeshift ) {
       return ( Employeeshift ) hibernateTemplate.merge( objEmployeeshift );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeshift deleteRecord( Employeeshift objEmployeeshift ) {
       hibernateTemplate.delete( objEmployeeshift );
       return objEmployeeshift;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeshift modifyRecord( Employeeshift objEmployeeshift ) {
       return ( Employeeshift ) hibernateTemplate.merge( objEmployeeshift );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Employeeshift> loadAll() {
       return (List<Employeeshift>)hibernateTemplate.findByNamedQuery( "Employeeshift.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeshift loadByPrimaryKey( Long primaryKey ) {
       return (Employeeshift) hibernateTemplate.get( Employeeshift.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Employeeshift deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Employeeshift> loadByHql(String query) {
       return ( List<Employeeshift> ) hibernateTemplate.find( query );
   }
}